Skip to content

refactor(config): pull up _parse_setting into BaseConfig - #2131

Closed
MrBubune wants to merge 1 commit into
commitizen-tools:masterfrom
MrBubune:refactor/config-pull-up
Closed

MrBubune wants to merge 1 commit into
commitizen-tools:masterfrom
MrBubune:refactor/config-pull-up

Conversation

@MrBubune

@MrBubune MrBubune commented Nov 25, 2026 •

Copy link
Copy Markdown

Description

Part of #2129.

JsonConfig, TomlConfig and YAMLConfig each had the same _parse_setting steps: parse the file, change a parse error into InvalidConfigurationError, then apply the commitizen section if it exists.

BaseConfig._parse_setting now runs these steps. Each subclass gives only:

  • _parse_errors: the parser errors for a malformed file
  • _missing_section_errors: the errors for a missing commitizen section
  • _load_document() and _get_commitizen_section()

The error types are the same as before, so behavior does not change.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines. AI suggested the changes; I wrote and reviewed the code by hand.

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Expected Behavior

No change. Valid, malformed and section-less config files behave as before.

Steps to Test This Pull Request

  1. uv run poe all
  2. uv run pytest tests/test_conf.py covers malformed files and missing sections for all three formats.

Additional Context

No new tests: the existing tests in tests/test_conf.py cover all paths. Pure refactor, so no docs change.

JsonConfig, TomlConfig and YAMLConfig repeated the same parse steps.
BaseConfig now runs these steps. Each subclass gives only its parser,
its parse errors and the path to its commitizen section.
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (fb3d172) to head (20cece2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2131   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files          61       61           
  Lines        2874     2875    +1     
=======================================
+ Hits         2825     2826    +1     
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@woile

woile commented Nov 26, 2026

Copy link
Copy Markdown
Member

Hi thanks for this but it doesn't add any value

@woile woile closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants